import { WebSocket } from "ws";
import { User } from "../../../types/User";
import { roomsTable } from "../../../database/rooms-table";
import { conversionMessage } from "../helpers/message-converter";
import { SelectRoomListMessageData } from "../types/MessageData";

export const selectRoomListHandler = ({ client }: { client: WebSocket; user: User; payload: SelectRoomListMessageData["payload"] }) => {
	client.send(conversionMessage({ type: "selectedRoomList", payload: { rooms: roomsTable.rooms.map((v) => ({ roomId: v.roomId, name: v.name })) } }));
};
